package mobi.hami.huapin.dao;

import mobi.hami.huapin.daobase.CrudMapper;
import mobi.hami.huapin.model.UserSession;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface UserSessionMapper  extends CrudMapper<UserSession> {

    @Select("select * from user_session where open_id = #{open_id} and user_id = #{user_id} LIMIT 1")
    UserSession findBy(@Param("open_id") String open_id,@Param("user_id") Integer user_id);


    /**
     *获取时间段内的登录用户
     * @param i MINUTE分钟数
     * @return
     */
    //@Select("select t.user_id from (SELECT user_id,(TIMESTAMPDIFF(MINUTE ,last_login_time,login_time)) ms from user_session) t where t.ms >=  #{i}")
    @Select("SELECT user_id from user_session where (TIMESTAMPDIFF(MINUTE ,last_login_time,login_time)) >=  #{i}")
    List<Integer> findUserIds(@Param("i") Integer i);


}
